<%-- 
    Document   : SearchTrip
    Created on : Apr 29, 2008, 4:58:12 AM
    Author     : Administrator
--%>
<%@ page import="java.util.*" %>
<%@ page import="Model.Model" %>
<%@ page import="Model.TripHandler" %>
<%@ page import="Database.Airlines" %>
<%@ page import="AirLine.Airline" %>
<%@ page import="AirLine.Airport" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>search trip</title>
    </head>
    <body>
        
        <%
            System.out.println("hello, wolrd");
        %>
        <form name="selection" 
              onsubmit="return cc()"
              method="POST"
              action="SearchTrip.do">
            Select a departure city:<p>
            Airport:
            <select name="cityFrom" size="1">
                <%
            Iterator it = ((Model) session.getAttribute("model")).getAirportsIterator();
            Airport tempAirport;
            while (it.hasNext()) {

                tempAirport = (Airport) it.next();

                out.print("<option value =\"" + tempAirport.getAirportCode() + "\">");
                out.print(tempAirport.getAirportName());
            }
                %>
            </select>
            <br><br>
            
            Select a destination city:<p>
            Airport:
            <select name="cityTo" size="1">
                <%

            it = ((Model) session.getAttribute("model")).getAirportsIterator();

            while (it.hasNext()) {
                tempAirport = (Airport) it.next();
                out.print("<option value =\"" + tempAirport.getAirportCode() + "\">");
                out.print(tempAirport);
            }
                %>
            </select>
            <br><br>
            Year:
            <select name="year" size="1">
                <option>2008
                <option>2009
                <option>2010
            </select>
            Month:
            <select name="month" size="1">
                <%
            for (int i = 1; i <= 12; i++) {
                out.print("<option>" + i);
            }
                %>
            </select>
            Day:              
            <select name="day" size="1">
                <%
            for (int i = 1; i <= 31; i++) {
                out.print("<option>" + i);
            }
                %>
            </select>
            <br><br>
            Number:
            <select name="number" size="1">
                <%
            for (int i = 1; i <= 10; i++) {
                out.print("<option>" + i);
            }
                %>
            </select>
            <br><br>
            Sort:
            <select name="sortingOrder" size="1">
                <option value ="<% out.print(TripHandler.SORT_BY_PRICE);%>">By Price
                <option value ="<% out.print(TripHandler.SORT_BY_TIME);%>">By Time
            </select>
            <br><br>
            Airlines:<br>
<%
            Iterator<Airline> itAirlines = ((Model) session.getAttribute("model")).getAirlinesIterator();
            while( itAirlines.hasNext() ){
                Airline airline = itAirlines.next();                   
%>

            <input type="checkbox" name="airlines" value="<%=airline.getCode()%>" checked="checked" /><%=airline.getName()%><br>
<%
            }
%>
            
            
            <input type="SUBMIT" value="gogogo">
        </form>
        
        
        
    </body>
    
    
    
</html>

<script language=Javascript> 
function cc(){ 
        

      var bb = document.selection.airlines;

      var flag = false;

      for(var j=0;j<bb.length;j++){

          if(bb[j].checked){

              flag = true;

           }

      }

      if(!flag){          
          alert("at least one airline");          
          return false;      
      }
   } 
</script>
